<script setup lang="ts">
withDefaults(
  defineProps<{
    selected?: boolean
  }>(),
  {
    selected: false
  }
)
</script>

<template>
  <div :class="['list-item', { playing: selected }]">
    <div class="cover">
      <slot name="avatar"></slot>
    </div>
    <div class="title-and-artist">
      <div class="container">
        <div class="title">
          <slot name="title"></slot>
        </div>
        <div class="artist">
          <slot name="description"></slot>
        </div>
      </div>
    </div>
    <div class="album">
      <slot></slot>
    </div>
    <div class="actions">
      <slot name="actions"></slot>
    </div>
    <div class="time">
      <slot name="suffix"></slot>
    </div>
  </div>
</template>

<style lang="less" scoped>
.list-item {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  &:hover {
    transition: all 0.3s;
    background: var(--color-secondary-bg);
  }
  &.playing {
    background: var(--color-primary-bg);
    .title,
    .artist,
    .album,
    .time {
      color: var(--color-primary) !important;
    }
  }
  .cover {
    border-radius: 8px;
    height: 46px;
    width: 46px;
    margin-right: 20px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    overflow: hidden;
  }
  .title-and-artist {
    flex: 1;
    display: flex;
    .container {
      display: flex;
      flex-direction: column;
      .title {
        font-size: 18px;
        font-weight: 600;
        color: var(--color-text);
        cursor: default;
        padding-right: 48px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        line-clamp: 1;
        -webkit-line-clamp: 1;
        overflow: hidden;
        word-break: break-all;
      }
      .artist {
        margin-top: 2px;
        font-size: 13px;
        opacity: 0.68;
        color: var(--color-text);
        display: -webkit-box;
        -webkit-box-orient: vertical;
        line-clamp: 1;
        -webkit-line-clamp: 1;
        overflow: hidden;
      }
    }
  }
  .album {
    font-size: 16px;
    opacity: 0.88;
    color: var(--color-text);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  .actions {
    display: flex;
    justify-content: flex-end;
    &:empty {
      display: none;
    }
    &:deep(button) {
      margin-left: 40px;
      .svg-icon {
        width: 20px;
        color: var(--color-primary);
      }
    }
  }
  .time {
    &:empty {
      display: none;
    }
    font-size: 16px;
    width: 80px;
    cursor: default;
    display: flex;
    justify-content: flex-end;
    margin-right: 10px;
    font-variant-numeric: tabular-nums;
    opacity: 0.88;
    color: var(--color-text);
  }
}
</style>
